package com.example.mvvmdemo.view;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.mvvmdemo.R;
import com.example.mvvmdemo.databinding.ActivityMvvmpatternBinding;
import com.example.mvvmdemo.viewmodel.MVVMDataViewModel;

public class MVVMActivity extends AppCompatActivity {

    private MVVMDataViewModel userViewModel;
    private TextView tvData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMvvmpatternBinding binding = DataBindingUtil.setContentView(this,
                R.layout.activity_mvvmpattern);
        userViewModel = new MVVMDataViewModel();
        binding.setUserViewModel(userViewModel);
        binding.setHandlers(this);

        tvData = binding.tvData;
    }

    public  void  onClickShowToastName(View view){
        Toast.makeText(this,tvData.getText().toString(),Toast.LENGTH_SHORT).show();
    }

    public void  onClickLoadData(View view){
        userViewModel.loadUserData();
    }
}
